<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<title>Da Milk</title>

<link rel=stylesheet href='css/main.css' type='text/css' />
<!-- *** Replace the key below below with your own API key, available at http://code.google.com/apis/maps/signup.html *** -->
<script src="http://www.google.com/jsapi?key=ABQIAAAAQ4VcutZ08P7TBvij8DvVmBR0FbdVKKGpLR36p2a-1juBdkpAZxSEFRtBmXIVeZf6hFr2-mwhKeql1g"></script>

<script type="text/javascript" src="js/lib/math3d.js"></script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script type="text/javascript" src="js/dojo/dojox/cometd.js.uncompressed.js"></script>
<script type="text/javascript" src="js/neighbour.js"></script>
<script type="text/javascript" src="js/chat.js"></script>
<script type="text/javascript" src="js/vehicle.js"></script>
<link rel="stylesheet" type="text/css" href="css/chat.css">
<script type="text/javascript">

var ge = null;
var geocoder;
var truck;
google.load("earth", "1");
google.load("maps", "2.99");
function el(e) {
	return document.getElementById(e);
}

function Sample(description, url) {
  this.description = description;
  this.url = url;
  return this;
}

var samples = [];

function init() {	
	google.load("earth", "1");
	google.load("maps", "2.99");		
	geocoder = new GClientGeocoder();
	google.earth.createInstance("map3d", initCallback, failureCallback);
}

function updateOptions() {
  var options = ge.getOptions();
  var form = document.options;

  options.setStatusBarVisibility(form.statusbar.checked);
  options.setMouseNavigationEnabled(form.mouseNav.checked);
  options.setScaleLegendVisibility(form.scaleLegend.checked);

  if (form.nav.checked) {
      ge.getNavigationControl().setVisibility(ge.VISIBILITY_SHOW);
    }
    else {
      ge.getNavigationControl().setVisibility(ge.VISIBILITY_HIDE);
    }

  if (form.berlin.checked) {
	berlinNetworkLink(true);

    }
    else {
	berlinNetworkLink(false);
  }
}

function berlinNetworkLink(enableLink){
	var networklink = ge.createNetworkLink("");
	var link = ge.createLink("");
	link.setHref('http://damilk.googlecode.com/svn/trunk/client/kml/start_berlin3d.kml');
	networklink.setLink(link);
	if (enableLink == true) {
		ge.getGlobe().getFeatures().appendChild(networklink);
	}
	else {
		ge.getFeatures().removeChild(networklink);
	}
}

function initCallback(object) {
	if (ge) ge=null;
	ge = object;
	ge.getWindow().setVisibility(true);
	// ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS, true);
	ge.getOptions().setFlyToSpeed(ge.SPEED_TELEPORT);

	//truck = new Truck();
	// berlinNetworkLink(true);
	updateOptions();
}

function run(){
	if (truck){
		truck.selfRemove();
	}
	truck = new Truck();
}
function failureCallback(err) {
  /***
   * This function will be called if plugin fails to load, in case
   * you need to handle that error condition.
   ***/
}

function submitLocation() {
  doGeocode(el('address').value);
}

function doGeocode(address) {
  geocoder.getLatLng(address, function(point) {
    if (point) {
      if (ge != null && truck != null) {
        truck.teleportTo(point.y, point.x);
      }
    }
  });
}
function modeldisappear() {
	  el("modelcars").style.display="none";
	  el("sim").style.display="block";	  
	
}
function simdisappear() {
	  el("sim").style.display="none";
	  el("modelcars").style.display="block";	  
	
}
  </script>
</head>
<body  onload='init()' onunload="GUnload()" onKeyDown="return keyDown(event);" onKeyUp="return keyUp(event);">

<span style="text-decoration:underline;cursor:pointer;" onclick="window.open('../truckserver/ModelFetcher','Choose a Model','width=300,height=400,left=100,top=200');">Choose Model</span>
<span style="text-decoration:underline;cursor:pointer;" onclick="run();">Run</span>
<input type="hidden" id="modelid">

<center>
<div id="sim" style="display:block">
  <div class="title">
    <center>
      <i>Da Milk</i>
    </center>
  </div>
 
 <div id="reportarea">
 Current Status:<div id="report">  
 </div>
  <div id='map3d_container' >
    <div id='map3d'></div>
  </div>
  <table>
    <tr>
      <td> To drive: use the buttons, or keyboard arrows (with focus on page).
        <div>
          <form name='searchform' id='searchform' action='javascript:submitLocation();void(0);'>
            <input type=text size=60 id='address' value='(enter a location to go there)'>
            </input>
            <input type=submit value='Teleport!'>
          </form>
          Presets:
          <input type=button value="Th' Plex" onclick="truck.teleportTo(37.423501,-122.086744,90);">
          <input type=button value="San Francisco" onclick="doGeocode('San Francisco');">
          <input type=button value="Whistler" onclick="truck.teleportTo(50.085734,-122.855824,220);">
          <input type=button value="Pismo" onclick="truck.teleportTo(35.040675,-120.629513,170);">
          <input type=button value="Tokyo" onclick="truck.teleportTo(35.668607,139.822026,180);">
          <input type=button value="Everest" onclick="truck.teleportTo(27.991283,86.924340,70);">
        </div></td>
      <td><table>
          <tr>
            <td></td>
            <td><input type=button class="button medw" onmousedown="gasButtonDown=true;" onmouseup="gasButtonDown = false;" value="gas"></td>
            <td></td>
          </tr>
          <tr>
            <td><input type=button class="button medw" onmousedown="leftButtonDown=true;" onmouseup="leftButtonDown=false;" value="left"></td>
            <td></td>
            <td><input type=button class="button medw" onmousedown="rightButtonDown=true;" onmouseup="rightButtonDown=false;" value="right"></td>
          </tr>
          <tr>
            <td></td>
            <td><input type=button class="button medw" onmousedown="reverseButtonDown=true;" onmouseup="reverseButtonDown=false;" value="reverse"></td>
            <td></td>
          </tr>
        </table></td>
    </tr>
  </table>

    <div id='options_container'>
      <form name="options" action='javascript:updateOptions();'>

        <input type="checkbox" onclick='updateOptions()' name="statusbar" checked />Status Bar&nbsp;&nbsp;&nbsp;
        <input type="checkbox" onclick='updateOptions()' name="mouseNav" checked />Mouse Navigation&nbsp;&nbsp;&nbsp;
		<input type="checkbox" onclick='updateOptions()' name="nav" checked />Nav Control&nbsp;&nbsp;&nbsp;
		<input type="checkbox" onclick='updateOptions()' name="berlin" />Berlin 3D&nbsp;&nbsp;&nbsp;
        <input type="checkbox" onclick='updateOptions()' name="scaleLegend" unckecked />Scale Legend&nbsp;&nbsp;&nbsp;
	  </form>
    </div>
</div>
</center>
</body>
</html>
